# 1. 线性回归模型
import numpy as np
from scipy.signal import cont2discrete
import matplotlib.pyplot as plt
import math
import LinearRegression

# 1.1 线性回归数据
x_T = np.array([[75,71,83,74,73,67,79,73,88,80,81,78,73,68,90]])
x = x_T.T
z_T = np.array([[183,175,187,185,176,176,185,191,195,185,174,180,178,170,184]])
z = z_T.T
# 1.2 调用线性回归函数
# 1.2.1 解析解求最优系数
# a = LinearRegression.linear_regression(x,z)

# 1.2.2 梯度下降法求最优系数
tol = 1e-4
alpha = np.array([[0.001,0],[0,0.00001]])
max_iter = 10000
a = LinearRegression.linear_regression_gd(x,z,alpha,max_iter,tol)
# # 1.3计算预测结果
y_delt = a[0,:]+a[1,:]*x
# 1.4 画图
plt.figure()
plt.scatter(x, z.flatten())
plt.plot(x, y_delt,marker='o',linestyle='--',color='r', label='Fitted Line')
plt.title('Simple Scatter Plot')
plt.xlabel('X Axis')
plt.ylabel('Y Axis')
plt.grid()
plt.show()

